//
//  YZLCarMessageTableViewCell.m
//  Car
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLCarMessageTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface YZLCarMessageTableViewCell ()

@property (nonatomic, strong) UIImageView *leftImage;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *author;
@property (nonatomic, strong) UILabel *comment;
@property (nonatomic, strong) UILabel *time;

@end

@implementation YZLCarMessageTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.leftImage];
        
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];
        self.title.font = [UIFont systemFontOfSize:15];
        self.title.numberOfLines = 2;
        
        self.time = [[UILabel alloc] init];
        self.time.textColor = [UIColor lightGrayColor];
        self.time.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.time];
        
        self.comment = [[UILabel alloc] init];
        self.comment.textColor = [UIColor lightGrayColor];
        self.comment.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.comment];
        
        self.author = [[UILabel alloc] init];
        self.author.textColor = [UIColor lightGrayColor];
        self.author.font = [UIFont systemFontOfSize:13];
        self.author.textAlignment = 2;
        [self.contentView addSubview:self.author];
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.leftImage.frame = CGRectMake(10, 5, 70, 60);
    self.title.frame = CGRectMake(90, 5, self.contentView.frame.size.width - 100, 40);
    self.time.frame = CGRectMake(90, 50, 80, 15);
    self.author.frame = CGRectMake(self.contentView.frame.size.width - 90, 50, 80, 15);
    self.comment.frame = CGRectMake(self.contentView.frame.size.width - 150, 50, 100, 15);
    
}

- (void)setModel:(YZLCarMessageModel *)model {
    
    if (_model != model) {
        _model = model;
    }
    
    [self.leftImage sd_setImageWithURL:[NSURL URLWithString:self.model.newsImage] placeholderImage:[UIImage imageNamed:@"D0"]];
    self.title.text = self.model.newsTitle;
    self.comment.text = [NSString stringWithFormat:@"💬 %@", self.model.commentCount];
    self.author.text = self.model.newsCategory;
    //日期格式转化
    NSDate  *date = [NSDate dateWithTimeIntervalSince1970:self.model.newsCreateTime];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate: date];
    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];
    NSString *timeStr = [NSString stringWithFormat:@"%@", localeDate];
    self.time.text = [timeStr substringToIndex:10];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
